﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using ReagentStore.BLL;
using ReagentStore.DAL;
using ReagentStore.ERM;

namespace ReagentStore
{
	public partial class CheckStockForm : Form
	{
		public CheckStockForm()
		{
			InitializeComponent();
		}

		private void CheckStockForm_Load(object sender, EventArgs e)
		{
			IList<Product> listExpiration = new ProductBLL().GetExpirationList();
			ReagentDAL dalReagent = new ReagentBLL().DALAccessor;
			foreach (var subitems in from product in listExpiration
			                         let reagent = dalReagent.GetEntityById(product.ReagentID)
			                         select new[]
			                                	{
			                                		reagent.Name,
			                                		product.Manufacturer,
			                                		product.Batch,
			                                		product.ExpirationDate.ToLocalTime().ToString("yyyy-MM-dd"),
			                                		product.Quantity().ToString() + reagent.Unit,
			                                	})
				listViewProduct.Items.Add(new ListViewItem(subitems));

			IList<Reagent> listLowQuantity = new ReagentBLL().GetAlertList();
			foreach (var subitems in listLowQuantity.Select(reagent => new[]
			                                                           	{
			                                                           		reagent.Name,
			                                                           		reagent.Quantity().ToString() + reagent.Unit,
			                                                           		reagent.AlertCount.ToString() + reagent.Unit
			                                                           	}))
				listViewReagent.Items.Add(new ListViewItem(subitems));
		}
	}
}